import HTMLParser
import urllib
import string


urlString = "http://www.ams-ix.net/connected"
urlText = []
pathOut = "ixp_members.txt"


class Parse19 (HTMLParser.HTMLParser):
    
    count = 0
    
    def handle_starttag (self, tag, attrs):
        if tag == "tr":
            self.count = 0
        if tag == "td":
            self.count += 1
    
    def handle_data (self, data):
        if self.count == 4:
            data = string.strip(data,'\n')
            if data not in urlText:
                urlText.append(data)
            self.count = 0


lparser = Parse19()
lparser.feed(urllib.urlopen(urlString).read())
fileOut = open(pathOut, "a")
for item in urlText:
    #print item # debug
    print >> fileOut, "19 %s" % item
fileOut.close()